from typing import List


def move_zeros(nums: List[int]) -> List[int]:
    """
    双指针，一次遍历
    :param nums:
    :return:
    """
    j = 0
    for i in range(len(nums)):
        if nums[i]:
            nums[j] = nums[i]
            if i != j:
                nums[i] = 0
            j += 1
    return nums


def move_zeros_2(nums: List[int]) -> List[int]:
    """
    双指针，两次遍历
    :param nums:
    :return:
    """
    j = 0
    for i in range(len(nums)):
        if nums[i]:
            nums[j] = nums[i]
            j += 1

    for k in range(j, len(nums)):
        nums[k] = 0

    return nums


def move_zeros_3(nums: List[int]) -> List[int]:
    """
    双指针，一次遍历，快排思想
    将非0放在左边，0放在右边
    :param nums:
    :return:
    """
    j = 0
    for i in range(len(nums)):
        if nums[i]:
            nums[i], nums[j] = nums[j], nums[i]
            j += 1
    return nums


if __name__ == '__main__':
    print(move_zeros_3(nums=[0, 4, 2, 1, 0, 4]))
